package com.fyzk.activity.prize;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.fyzk.bean.JLPrizeInfo;
import com.tyjc.lottery.R;

import java.util.List;

public class JCLQ_PrizeAdapter extends BaseAdapter{
	
	private int tv_saiGuo;
	protected List<JLPrizeInfo> list_infor;
	private Context context;
	
	protected LayoutInflater myInflater;
	protected Resources myResources;

	protected JCLQ_PrizeAdapter(Context context, List<JLPrizeInfo> list_infor){
		this.context = context;
		this.myInflater = LayoutInflater.from(context);
		this.myResources = context.getResources();
		this.list_infor = list_infor;
	}
	
	@Override
	public int getCount() {
		return list_infor.size();
	}

	@Override
	public Object getItem(int arg0) {
		return list_infor.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		JLPrizeInfo infor = list_infor.get(position);
		
		convertView = myInflater.inflate(R.layout.kaijiang_lishi_jclq, null);
		ViewHolder holder = new ViewHolder();
		
		holder.saiShi = (TextView)convertView.findViewById(R.id.kjls_jclq_saiShi);
		holder.id = (TextView)convertView.findViewById(R.id.kjls_jclq_id);
		holder.time = (TextView)convertView.findViewById(R.id.kjls_jclq_time);
		holder.zhu = (TextView)convertView.findViewById(R.id.kjls_jclq_home);
		holder.ke = (TextView)convertView.findViewById(R.id.kjls_jclq_away);
		holder.biFen = (TextView)convertView.findViewById(R.id.kjls_jclq_biFen);
		
		holder.sf = (TextView)convertView.findViewById(R.id.kjls_jclq_sf);
		holder.rfsf = (TextView)convertView.findViewById(R.id.kjls_jclq_rfsf);
		holder.dxf = (TextView)convertView.findViewById(R.id.kjls_jclq_dxf);
		holder.sfc = (TextView)convertView.findViewById(R.id.kjls_jclq_sfc);
		holder.zong_cf = (TextView)convertView.findViewById(R.id.kjls_jclq_zong);
		
		convertView.setTag(holder);
		
		holder.saiShi.setText(infor.getMatchName());
		holder.id.setText(infor.getMatchNum());
		holder.time.setText(infor.getOfficialWeekDay());
		holder.zhu.setText(infor.getHomeTeam());
		holder.ke.setText(infor.getAwayTeam());
		holder.biFen.setText(infor.getAwayScore()+":"+infor.getHomeScore());
		
		int homeScore = 0;
		int awayScore = 0;
//		if(infor.score.contains(":")){
//			try {
				homeScore = infor.getHomeScore();
				awayScore = infor.getAwayScore();
//			} catch (Exception e) {
//				// TODO: handle exception
//			}
//		}
		holder.zong_cf.setText("总分"+(homeScore+awayScore)+" 分差"+(homeScore-awayScore));
		
		String rang = infor.getHandicap();
		holder.sf.setText(infor.getSfResult());
		holder.rfsf.setText("("+rang+")"+infor.getRqSfResult());
		holder.dxf.setText(infor.getDxfResult());
		holder.sfc.setText(infor.getSfcResult());
		
		
		
		if (infor.getSfResult().equals("胜")) {
			tv_saiGuo = myResources.getColor(R.color.top_bg);
		}else{
			tv_saiGuo = myResources.getColor(R.color.kaijiang_jc_tv_fu);
		}
		
//		holder.ll_saiGuo.setBackgroundColor(bg_saiGuo);
//		holder.saiGuo.setTextColor(tv_saiGuo);
		holder.biFen.setTextColor(tv_saiGuo);

		return convertView;
	}
	
	public void setList_infor(List<JLPrizeInfo> list_infor) {
		this.list_infor = list_infor;
		this.notifyDataSetChanged();
	}
	
	class ViewHolder {
		TextView saiShi;
		TextView id;
		TextView time;
		TextView zhu;
		TextView ke;
		TextView saiGuo;
		TextView biFen;
		
		TextView sf;
		TextView rfsf;
		TextView dxf;
		TextView sfc;
		TextView zong_cf;
	}

}
